<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1" import="java.util.ArrayList, db.*"%>
<!DOCTYPE html">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black" />
<meta name="viewport"
	content="user-scalable=no, width=device-width, initial-scale=1.0, maximum-scale=1.0" />
<!-- Icons for Web App
<link rel="apple-touch-icon" sizes="114x114" href="images/nav/index@2x.png">
<link rel="apple-touch-startup-image" href="images/splash/splash-screen.png" media="screen and (max-device-width: 320px)" />
<link rel="apple-touch-startup-image" media="(max-device-width: 480px) and (-webkit-min-device-pixel-ratio: 2)" href="images/splash/splash-screen@2x.png" />
-->
<title>Frontera Pesos</title>
<link href="styles/style.css" rel="stylesheet" type="text/css">
<link href="styles/type.css" rel="stylesheet" type="text/css">
<link href="styles/buttons.css" rel="stylesheet" type="text/css">
<link rel="stylesheet"
	media="only screen and (-webkit-min-device-pixel-ratio: 2)"
	type="text/css" href="styles/highdpi.css" />
<!-- utility js -->
<script type="text/javascript" src="../scripts/fronteraWebUtility.js"></script>

<% //DBHelper helper = new DBHelper();
	Coupons coupons = new Coupons();
	FormatAndValidation fav = new FormatAndValidation();

    String serverName =  request.getRemoteHost();
	String _errorMessage = "";
	String _userName = "";
	String _loginID = "";
	String displayRewardsSec = "none";
	int storeCkInId = 0;
	int admin = 0;
	int server = 0;
	int checkID = 0;
	String showAdminBtn = "none";
	String showServerBtn = "none";
	
	Cookie[] cookies = request.getCookies();
	ArrayList<UserData> userInfo =  new ArrayList<UserData>();
	ArrayList<Coupons> couponInfo =  new ArrayList<Coupons>();
	ArrayList<Campaign> campaignInfo =  new ArrayList<Campaign>();
	ArrayList<StoreLocation> storeInfo =  new ArrayList<StoreLocation>();
	//campaignInfo = helper.getAllCampaigninfo();
 	%>
<script>
function formSubmitRule(formName,task,itemId,arrayId)
{
	var e = document.getElementById(formName);
	//alert(e.name + " " + itemId + " form name");
	//alert("send user to edit page = " + task);
	if(task == "update")
		{
			if(formName == "editPromo")
				{
					var UrlLink = "admin-viewEditPromo.jsp?aID="+arrayId+"&itemID="+itemId;
					window.location.href=UrlLink;
					return;
				}
			else if(formName == "editCampaignPromo")
			{
				var UrlLink = "admin-viewEditCampaign.jsp?aID="+arrayId+"&itemID="+itemId;
				window.location.href=UrlLink;
				return;
			}
			
	//	alert(formName);
		//alert("send user to edit page = " + task);
		}
	 else if (task ==  "Delete")
	 {
		
		 if(formName == "editPromo")
			{
			 var answer = confirm("Are you sure you would like to remove this Promo?");
				if(answer)
						{
					//alert(e.name + " " + itemId + " form test name");
					
					//document.forms[formName]["typeName"].value = formName;
					//document.forms[formName]["typeID"].value = itemId;
							e.typeName.value = formName; 
							e.typeID.value = itemId;
							
							
							//var t = document.forms[formName]["typeName"].value;
							//var oo = document.forms[formName]["typeID"].value;
							//alert("e.typeID.value = " + e.typeID.value);
							////alert("e.typeName.value = " + e.typeName.value);
							document.getElementById(formName).submit();
							
					    	
								
						}
					else
						{
						 return;
						}
			}
		else if(formName == "editCampaignPromo")
		{
			var answer = confirm("Are you sure you would like to remove this Campaign?");
			if(answer)
					{
						e.typeName.value = formName;
						e.typeID.value = itemId;
						document.getElementById(formName).submit();
				   
				    	
							
					}
				else
					{
					 return;
					}
		}
		
	//alert(formName);
	//alert("send user to edit page = " + task);
	 
	 
	 }

	
//document.getElementById("addrule").submit();
}
function adminPage()
{
	var UrlLink = "admin-view.jsp";
	window.location.href=UrlLink;

}
function submitRule(formName)
{
	document.getElementById(formName).submit();
}


</script>
<style type="text/css">
table {
	border: solid #666 medium;
	margin-left: auto;
	margin-right: auto;
}

tr:nth-child(even) {
	background: #FFF;
}

tr:nth-child(odd) {
	background: #EEE;
}

.toprow {
	background-color: #CCC;
	font-size: 1.5em;
}

.td {
	border: 1px solid #000;
}

h5 {
	padding: 4px;
	font-size: .7em;
}
</style>
</head>
<body>


	<%
	if(campaignInfo.size() != 0)
	{
	 for(int i = 0; i < campaignInfo.size(); i++) {
			System.out.println(" campaignInfo " + campaignInfo.get(i).getCampaignName());
	 }
	 
	 couponInfo = coupons.getAllCouponsinfo();
	 	
 	 for(int i = 0; i < couponInfo.size(); i++) {
 			System.out.println(" couponInfo " + couponInfo.get(i).getCouponName());
 	 }
	}
	%>

	<% 

if(session.getAttribute("userInfo") != null)
	{
		Object t = session.getAttribute("userInfo");
		userInfo = (ArrayList<UserData>) t;
		 for(int i = 0; i < userInfo.size(); i++) {
				System.out.println(" userdata " + userInfo.get(i).getPhoneNumber());
		 }
	} 
if(session.getAttribute("checkinID") != null)
{
	   
	    Object g =  session.getAttribute("checkinID");
	    checkID = Integer.parseInt(g.toString());
	    
}
if(session.getAttribute("couponInfo") != null)
{
	Object t = session.getAttribute("couponInfo");
	couponInfo = (ArrayList<Coupons>) t;
	 for(int i = 0; i < couponInfo.size(); i++) {
			System.out.println(" couponInfo " + couponInfo.get(i).getCouponName());
	 }
}	
if(session.getAttribute("storeInfo") != null)
	{
		Object t = session.getAttribute("storeInfo");
		storeInfo = (ArrayList<StoreLocation>) t;
		 for(int i = 0; i < storeInfo.size(); i++) {
				System.out.println(" storeInfo " + storeInfo.get(i).getStoreName());
		 }
	}
if(session.getAttribute("campaignInfo") != null)
{
	Object t = session.getAttribute("campaignInfo");
	campaignInfo = (ArrayList<Campaign>) t;
	 for(int i = 0; i < campaignInfo.size(); i++) {
			System.out.println(" campaignInfo " + campaignInfo.get(i).getCampaignName());
	 }
}

if(session.getAttribute("displayRewardsSec") != null)
{
	   
	    Object g =  session.getAttribute("displayRewardsSec");
	    displayRewardsSec = g.toString();
	    
}
if(session.getAttribute("storeCkInId") != null)
{
	   
	    Object g =  session.getAttribute("storeCkInId");
	    storeCkInId = Integer.parseInt(g.toString());
	    
	    System.out.println(" storeCkInId ==  " + storeCkInId);
}

if(session.getAttribute("adminRights") != null)
{
	   
	    Object g =  session.getAttribute("adminRights");
	    admin = Integer.parseInt(g.toString());
	    if(admin == 1)
		{
	    	 showAdminBtn = "inline";
		}
	   
	   
	    System.out.println(" showAdminBtn ==  " + admin);
}
if(session.getAttribute("serverRights") != null)
{
	   
	    Object g =  session.getAttribute("serverRights");
	    server = Integer.parseInt(g.toString());
	    if(server == 1)
		{
	    	showServerBtn = "inline";
		}
	    
	    System.out.println(" showServerBtn ==  " + server);
}


if(session.getAttribute("errorMessage") != null)
  {
    Object g =  session.getAttribute("errorMessage");
    _errorMessage = g.toString();
 }
else if(session.getAttribute("errorMessage") != null && session.getAttribute("errorMessage") == "")
{
	 _errorMessage = "";
}
  else
  {
   _errorMessage = "";
  }
	%>
	<%if(session.getAttribute("isCheckedIn") != null)
{ 
		Object g =  session.getAttribute("isCheckedIn");
		int iCk = Integer.parseInt(g.toString());
	
	if(iCk == 1)
	{
		%>
	<script type="text/javascript">
		alert("You are checked in already!");
	</script>
	<%} 
	session.setAttribute("isCheckedIn",0);
} 


%>
	<div class="landing-page">
		<p class="center-text landing-logo shadow">
			<img class="replace-2x" width="200" src="../assets/FroLogoRetina.png"
				alt="img">

		</p>

		<center>
			<div id="errorTxt" class="errorMessageTxt"><%=_errorMessage %></div>

			<div class="tablet-box-expanded" style="width: 780px;">

				<div class="tablet-customer" style="width: 780px;">

					<p>
						<span style="display:<%=showAdminBtn%>"> <a href="#">Administration</a>
							- <a href="admin-view-customer.jsp">Customer Info</a> - <a
							href="server.jsp" style="display:<%=showServerBtn%>">Server</a> -

						</span> <span> <a href="admin-view-faq.html">Faq</a> - <a
							href="userHomePage.jsp">Home</a>
						</span>
					</p>

					<p>
						<span> <a href="javascript:void(0);"
							onClick="logUserOut();"><strong>Logout</strong></a></span>
					</p>

					<p>&nbsp;</p>
					<h2>Promo Rules</h2>
					<p>&nbsp;</p>
					<form name="editPromo" id="editPromo" method="post"
						action="../Admin">
						<input type="hidden" name="typeID" id="typeID" value="" /> <input
							type="hidden" name="typeName" id="typeName" value="" /> <input
							type="hidden" name="adminRequestType" id="adminRequestType"
							value="deleteCoupon" />

						<table style="width: 745">
							<tr class="toprow">
								<td><h5>Promo Name</h5></td>
								<td><h5>Pesos</h5></td>
								<td><h5>Active</h5></td>
								<td><h5>Start Date</h5></td>
								<td><h5>End Date</h5></td>
								<td><h5>Remove</h5></td>
								<td><h5>Update</h5></td>
							</tr>
							<% for(int i = 0; i < couponInfo.size(); i++) { 
     System.out.println(" coupons admin page "+ i);
     		if(couponInfo.get(i).getBirthdayPromo()== 0)
     		{
     			
     			%>

							<tr>
								<td><%=couponInfo.get(i).getCouponName()%></td>
								<td><%=couponInfo.get(i).getPointValue()%></td>
								<td>
									<%if(couponInfo.get(i).getActive()== 1)
            	{%> <img src="../assets/tick.png" alt="img"
									class="replace-2x">&nbsp; <%}
            	else 
            	{%> &nbsp; <%} %>
								</td>
								<td><%=fav.convertDateForHtml(couponInfo.get(i).getBeginDatetime()) %></td>
								<td><%=fav.convertDateForHtml(couponInfo.get(i).getEndDatetime()) %></td>
								<td><a href="javascript:void(0)"
									onClick="formSubmitRule('editPromo','Delete',<%=couponInfo.get(i).getCouponId() %>,<%=i%>)"
									title="Delete"> <img src="../assets/cross.png" alt="img"
										class="replace-2x">
								</a></td>
								<td><a href="javascript:void(0)"
									onClick="formSubmitRule('editPromo','update',<%=couponInfo.get(i).getCouponId() %>,<%=i%>)"
									title="Update"> <img src="../assets/update.jpg" alt="img"
										width="70" class="replace-2x">
								</a></td>
							</tr>
							<%} }%>
						</table>
					</form>
					<form name="editCampaignPromo" id="editCampaignPromo" method="post"
						action="../Admin">
						<input type="hidden" name="typeID" id="typeID" value="" /> <input
							type="hidden" name="typeName" id="typeName" value="" /> <input
							type="hidden" name="adminRequestType" id="adminRequestType"
							value="deleteCoupon" />

						<h2>&nbsp;</h2>
						<h2>Campaign Rules</h2>
						<p>&nbsp;</p>
						<table style="width: 745">
							<tr class="toprow">
								<td><h5>Campaign Name</h5></td>
								<td><h5>Peso Multiplier</h5></td>
								<td><h5>Active</h5></td>
								<td><h5>Start Date</h5></td>
								<td><h5>End Date</h5></td>
								<td><h5>Remove</h5></td>
								<td><h5>Update</h5></td>
							</tr>
							<% for(int p = 0; p < campaignInfo.size(); p++) { 
     System.out.println(" coupons admin page "+ p);
     		if(campaignInfo.get(p).getBirthdayPromo()== 0)
     		{
     			%>

							<tr>
								<td><%=campaignInfo.get(p).getCampaignName()%></td>
								<td><%=campaignInfo.get(p).getPointMultiplier()%></td>
								<td>
									<%if(campaignInfo.get(p).getActive()== 1)
            	{%> <img src="../assets/tick.png" alt="img"
									class="replace-2x">&nbsp; <%}
            	else 
            	{%> &nbsp; <%} %>
								</td>
								<td><%=fav.convertDateForHtml(campaignInfo.get(p).getBeginDatetime())%></td>
								<td><%=fav.convertDateForHtml(campaignInfo.get(p).getEndDatetime())%></td>

								<td><a href="javascript:void(0)"
									onClick="formSubmitRule('editCampaignPromo','Delete',<%=campaignInfo.get(p).getCampaignId() %>,<%=p%>)"
									title="Delete"> <img src="../assets/cross.png" alt="img"
										class="replace-2x">
								</a></td>
								<td><a href="javascript:void(0)"
									onClick="document.addcampaign.isUpdate.value = 1;formSubmitRule('editCampaignPromo','update',<%=campaignInfo.get(p).getCampaignId() %>,<%=p%>)"
									title="Update"> <img src="../assets/update.jpg" alt="img"
										width="70" class="replace-2x">
								</a></td>
							</tr>
							<%} }%>

						</table>
						<input type="hidden" name="arrayID" />
					</form>
					<form name="editBirthdayPromo" id="editBirthdayPromo" method="post"
						action="../Admin">
						<input type="hidden" name="typeID" id="typeID" value="" /> <input
							type="hidden" name="typeName" id="typeName" value="" /> <input
							type="hidden" name="adminRequestType" id="adminRequestType"
							value="deleteCoupon" />

						<h2>&nbsp;</h2>
						<h2>Birthday Promo</h2>
						<p>&nbsp;</p>

						<table style="width: 745">
							<tr class="toprow">
								<td><h5>Birthday Promo</h5></td>
								<td><h5>Peso Multiplier</h5></td>
								<td><h5>Remove</h5></td>
								<td><h5>Update</h5></td>
							</tr>
							<% for(int n = 0; n < campaignInfo.size(); n++) 
           { 
     
     		if(campaignInfo.get(n).getBirthdayPromo()== 1)
     		{
     			%>

							<tr title="<%=campaignInfo.get(n).getCampaignDesc()%>">
								<td><%=campaignInfo.get(n).getCampaignName()%></td>
								<td><%=campaignInfo.get(n).getPointMultiplier()%></td>

								<td><a href="javascript:void(0)"
									onClick="formSubmitRule('editCampaignPromo','Delete',<%=campaignInfo.get(n).getCampaignId() %>,<%=n%>)"
									title="Delete"> <img src="../assets/cross.png" alt="img">
								</a></td>
								<td>
									<%System.out.println(" campaignInfo new page "+ campaignInfo.get(n).getCampaignId() + " " + campaignInfo.get(n).getCampaignName()); %>
									<a href="javascript:void(0)"
									onClick="formSubmitRule('editCampaignPromo','update',<%=campaignInfo.get(n).getCampaignId()%>,<%=n%>)"
									title="Update"> <img src="../assets/update.jpg" alt="img"
										width="70">
								</a>

								</td>
							</tr>
							<%} }%>
						</table>
						<p></p>
						<p>&nbsp;</p>
						<p>&nbsp;</p>
					</form>
					<div
						style="width: 200px; border: solid #666 medium; padding: 15px; position: relative; float: left; margin-left: 20px; margin-right: 18px;">
						<h2>Add Promo</h2>
						<br />
						<form name="addrule" method="post" id="addrule" action="../Admin">
							<!-- isUpdate // 1 = update 0 = insert
          -->
							<input type="hidden" name="isUpdate" id="isUpdate" value="0" />
							<input type="hidden" name="typeName" id="typeName" value="promo" />
							<input type="hidden" name="adminRequestType"
								id="adminRequestType" value="addCoupon" />
							<p>
								<label for="promoname2">Promo Name</label> <input
									name="promoname" class="text-input" value="test" id="textfield"
									type="text" style="background-image: none;" /> <br /> <br /> <label
									for="pesoamount2">Pesos Amount</label> <input
									name="promoamount" class="text-input" value="25" id="textfield"
									type="text" style="background-image: none;" />
							</p>
							<p>&nbsp;</p>
							<p>
								<label for="promostartdate">Start Date<br> <input
									name="promostartdate" type="date" value="03/25/2013"
									id="textfield" placeholder="mm/dd/yyyy">
								</label>
							</p>
							<p>
								<br> <label for="promoenddate">End Date<br> <input
									name="promoenddate" type="date" value="03/26/2014"
									id="textfield" placeholder="mm/dd/yyyy">
								</label> <br /> <br /> <label for="setinitialstatus2">Active
									upon Submission?</label> <br /> Yes <input name="setinitialstatus"
									type="radio" value="1" checked> No <input
									name="setinitialstatus" type="radio" value="0"> <br />
								<br />
							<p>&nbsp;</p>
							<p>
								Is this a birthday promo?<br /> Yes <input
									name="setbirthdaypromo" type="radio" value="1"> No <input
									name="setbirthdaypromo" type="radio" value="0" checked>
							<p>
								<br /> <br /> <span class=""><a class="buttonBigYellow"
									onclick="submitRule('addrule')" href="javascript:void(0)">Add
										Rule</a></span>
							</p>
						</form>
					</div>
					<div
						style="width: 200px; border: solid #666 medium; padding: 15px; position: relative; float: right; margin-right: 17px;">
						<h2>Add Campaign</h2>
						<br />
						<form name="addcampaign" id="addcampaign" method="post"
							action="../Admin">
							<!-- isUpdate // 1 = update 0 = insert
          -->
							<input type="hidden" name="isUpdate" id="isUpdate" value="0" />
							<input type="hidden" name="typeName" id="typeName"
								value="campaign" /> <input type="hidden"
								name="adminRequestType" id="adminRequestType" value="addCoupon" />

							<p>
								<label for="campaignname">Campaign Name</label> <input
									name="campaignname" class="text-input" id="textfield"
									type="text" value="Test campaign"
									style="background-image: none;" /> <br />
								<br /> <label for="pesoamount">Pesos Multiplier</label> <input
									name="pesoamount" class="text-input" id="textfield" type="text"
									value="2" style="background-image: none;" /> <br />
								<br /> <label for="campaigndatestart">Start Date<br>
									<input name="campaigndatestart" type="date" id="textfield"
									value="03/25/2013" placeholder="mm/dd/yyyy"></label>
							</p>
							<p>
								<br> <label for="campaigndateend">End Date<br>
									<input name="campaigndateend" type="date" value="03/26/2014"
									id="textfield" placeholder="mm/dd/yyyy"> <br> <br>
									<br> Active upon Submission?
								</label>
							</p>
							<p>
								Yes <input name="setinitialstatus" type="radio" value="1"
									checked> No <input name="setinitialstatus" type="radio"
									value="0"><br />
								<br />
							<p>&nbsp;</p>
							<p>
								Is this a birthday promo?<br /> Yes <input
									name="setbirthdaypromo" type="radio" value="1"> No <input
									name="setbirthdaypromo" type="radio" value="0" checked>
							<p>
								<br /> <br /> <span class=""><a class="buttonBigYellow"
									onclick="submitRule('addcampaign')" href="javascript:void(0)">Add
										Campaign</a></span>
							</p>
						</form>
					</div>


					<div
						style="width: 200px; border: solid #666 medium; padding: 15px; float: left; margin-bottom: 15px;">
						<h2>Edit Customer</h2>
						<br />
						<form name="editcustomer" id="editcustomer" method="post"
							action="../Admin">
							<input type="hidden" name="typeName" id="typeName"
								value="editcustomer" /> <input type="hidden"
								name="adminRequestType" id="adminRequestType" value="searchCust" />
							<p>
								<label for="email">Email</label> <input name="customeremail"
									class="text-input" id="textfield" type="text"
									style="background-image: none;" /> <br /> <strong>or</strong>
							</p>
							<p>
								<br /> <label for="phonenumber">Phone Number </label><input
									name="phonenumber" value="678-523-7250" class="text-input"
									id="textfield" type="text" style="background-image: none;" />
								<br /> <br /> <span class=""><a href="javascript:void(0)"
									class="buttonBigYellow" onclick="submitRule('editcustomer')">Search</a></span>
							</p>
						</form>
					</div>



				</div>
			</div>

		</div>


		<!--	<p class="login-note shadow"><strong>*</strong>Forgot my Password</p> -->
		<div style="height: 25px;"></div>
	</center>


</body>
</html>